use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use yata::core::PeriodType;
use yata::core::ValueType;

use super::IndicatorActionWrap;

///
/// Struct to hold the results of Struct yata::indicators::ChandeKrollStop
///
///  参见[CKS](https://tradingview.com/support/solutions/43000589105-chande-kroll-stop/)
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct CKS {
    ///2 signals
    ///signal 1 is calculated according to relative position of the source value between stop short and stop long values.
    ///When source value goes above stop short, then returns full buy signal.
    ///
    ///When source value goes below stop long, then returns full sell signal.
    ///
    pub signal0: Option<IndicatorActionWrap>,
    ///signal 2 appears only when stop long crosses stop short upwards.
    ///When cumulative move of stop short and stop long is upwards, then returns full buy.
    ///
    ///When cumulative move of stop short and stop long is downwards, then returns full sell.
    pub signal1: Option<IndicatorActionWrap>,

    ///3 values
    ///stop long Range of values is the same as the range of the source values.
    ///
    pub stop_long: ValueType,

    ///source value
    ///
    pub source: ValueType,

    ///stop short
    ///
    ///Range of values is the same as the range of the source values.
    ///
    pub stop_short: ValueType,
}

/// Configuration for Struct yata::indicators::AwesomeOscillator, Awesome Oscillator
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct CKSConfig {
    ///  ma: M
    ///  ATR moving average.
    ///  
    ///  Default is SMA(10).
    ///  
    ///  Range in [1; PeriodType::MAX]
    ///  
    pub ma: PeriodType,

    ///  x: ValueType
    ///  ATR multiplier. Default is 1.0.
    ///  
    ///  Range in [0; +inf)
    ///  
    pub x: ValueType,

    ///  q: PeriodType
    ///  multiplied highest/lowest period length. Default is 9.
    ///  
    ///  Range in [1; PeriodType::MAX]
    ///  
    pub q: PeriodType,
    //  source: Source
    //  Price source. Default is Close
}

impl Default for CKSConfig {
    fn default() -> Self {
        Self {
            ma: 10,
            x: 1.0,
            q: 9,
        }
    }
}
